package reflect.method;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class Demo2 {
    public static void main(String[] args) throws Exception {
        //获取字节码文件对象
        Class<Student> aClass = (Class<Student>)Class.forName("reflect.method.Student");
        //通过反射获取空参构造
        Constructor<Student> constructor = aClass.getConstructor();
        //通过空参构造创建Student对象
        Student student = constructor.newInstance();
        /*//获取Method对象
        Method function1 = aClass.getMethod("function1");
        //通过Method对象调用invoke方法
        //如果方法无参，那么invoke返回的就是null
        Object invoke = function1.invoke(student);
        System.out.println(invoke);*/
        /*Method function4 = aClass.getMethod("function4", String.class);
        Object y = function4.invoke(student, "于飞正");
        System.out.println(y);*/
        Method show = aClass.getDeclaredMethod("show");
        show.setAccessible(true);
        Object invoke = show.invoke(student);
        System.out.println(invoke);
    }
}
